package br.unicamp.integralization.dto;

import java.util.ArrayList;
import java.util.List;

public class History implements Cloneable {

	private Student student;
	private String course;
	private String modality;
	private String option;
	private List<Subject> subjects;
	private Allocation allocation;

	public History() {
		student = new Student("", "");
		course = modality = option = "";
		subjects = new ArrayList<Subject>();
		allocation = new Allocation();
	}

	@Override
	public History clone() {
		History h = new History();
		h.student = this.student;
		h.course = this.course;
		h.modality = this.modality;
		h.option = this.option;
		h.subjects = new ArrayList<Subject>();
		for (Subject sub : this.subjects) {
			h.subjects.add(sub);
		}
		
		h.allocation = this.allocation.clone();

		return h;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	public String getCourse() {
		return course;
	}

	public void setCourse(String course) {
		this.course = course;
	}

	public String getModality() {
		return modality;
	}

	public void setModality(String modality) {
		this.modality = modality;
	}

	public String getOption() {
		return option;
	}

	public void setOption(String option) {
		this.option = option;
	}

	public List<Subject> getSubjects() {
		return subjects;
	}

	public void setSubjects(List<Subject> subjects) {
		this.subjects = subjects;
	}

	public Allocation getAllocation() {
		return allocation;
	}

	public void setAllocation(Allocation allocation) {
		this.allocation = allocation;
	}

	
	@Override
	public String toString(){
		StringBuilder builder = new StringBuilder();
		builder.append("Histórico do aluno:\n");
		int sum=0;
		for (Subject subject : subjects) {
			sum+=subject.getCredits();
		}
		
		builder.append("Matérias feitas ("+ sum+" créditos):\n");
		for (int i = 0; i < subjects.size(); i++) {
			builder.append(subjects.get(i)+ " ");
			if((i+1)%5==0){
				builder.append("\n");
			}
		}
		builder.append("\nCatálogo:\n");
		builder.append(getAllocation());
		
		return builder.toString()+"\n";
	}
}
